package cn.tedu.micro.service.stock.controller;

import cn.tedu.micro.service.common.JsonResult;
import cn.tedu.micro.service.stock.service.StockService;
import io.seata.core.context.RootContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stock")
public class StockController {
    @Autowired
    private StockService stockService;

    @PostMapping("/reduce")
    public JsonResult reduceStock(@RequestParam("productCode") String productCode,
                                  @RequestParam("count") Integer count){
        Boolean result = stockService.reduceStock(productCode, count);
        if(!result)
           return JsonResult.fail("库存不足");
        System.out.println("==============="+ RootContext.getXID() +"====================");
        return JsonResult.ok();
    }
}
